<template>
	<ui-sys img="https://cos.color-ui.com/img/4put2.png" tabbar>
		<ui-navbar :back="false" opacity :placeholder="false">
			<view class="flex-bar p-3" v-if="sys_scrollTop > sys_navBar">
				<text class="text-lg cicon-goods-o text-red mx-3"></text>
				<text class="text-lg text-bold">题库</text>
			</view>
			<view class="p-3 flex-bar flex-sub" v-if="sys_scrollTop > sys_navBar">

			</view>
			<view class="flex-bar">
				<!-- #ifdef MP -->
				<view :style="{ width: `${sys_capsule.width + 10}px`, height: `${sys_capsule.height}px` }"></view>
				<!-- #endif -->
			</view>
		</ui-navbar>
		<view class="header">
			<view class="title ml-5">
				<text class="text-40  text-bold">题库</text>
			</view>
			<view @tap="handlePublishUser(userInfo.uid)">
				<ui-avatar v-if="isLogin" ui="round sl mr-5" :src="userInfo.avatarUrl">
				</ui-avatar>
			</view>
		</view>
		<view class="questionBox">
			<view @click="handleArea(item)" class="item" v-for="item in areaList" :key="item.id">
				<image :src="item.icon" mode="aspectFit"></image>
				<view class="name">{{ item.name }}</view>
			</view>
		</view>
	</ui-sys>
</template>

<script>
	import {
		getStorageUserInfo
	} from '@/utils/storageUtils.js'

	import {
		classRequest
	} from '@/api/question.js';
	export default {
		data() {
			return {
				isLogin: false,
				userInfo: null,
				areaList: []
			};
		},
		onLoad() {
			this.checkLogin()
			this.getQuestionClass()
		},
		methods: {
			// 检查登陆状态
			checkLogin() {
				this.userInfo = getStorageUserInfo()
				if (this.userInfo != null) {
					this.isLogin = true
				} else {
					this.isLogin = false
				}
			},
			// 进入个人中心
			handlePublishUser(_id) {
				uni.navigateTo({
					url: `/pages/my/info?userID=${_id}`,
				});
			},
			// 跳转到 题目列表页面
			handleArea(item) {
				uni.navigateTo({
					url: `/pages/question/list?areaID=${item.id}&areaName=${encodeURIComponent(item.name)}`
				})

			},
			getQuestionClass() {
				classRequest().then(res => {
					if (res.code != 200) {
						this.$Tips('请求失败');
						return
					}
					this.areaList = res.data
				})

			}
		}
	};
</script>

<style lang="scss">
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 100rpx;
		padding-bottom: 10rpx;
	}

	.questionBox {
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
		flex-wrap: wrap;
		width: 690rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		background-color: #fff;
		border-radius: 16rpx;
		padding-bottom: 50rpx;

		.item {
			width: 33.33%;
			text-align: center;
			margin-top: 50rpx;

			image {
				width: 150rpx;
				height: 150rpx;
			}

			.name {
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>
